
package instrumentation;


import java.io.Serializable;
import java.util.Comparator;
import java.util.List;
import java.util.Map;

import operations.ValuesGenerator;

import model.Filter;




public abstract class Condition  implements Serializable{


	public enum DataType {
		Boolean, Character, Number, String, Array, Reference
	}

	private final int branchId;
	private final int switchCaseId;
	private final DataType dataType;
	private final Value v1;
	private final DataUse use1;
	private final DataUse use2;
	private final Value v2;
	private final BlockMethodCall methodCall;
	public Condition(int branchId, DataType dataType, 
				Value v1,DataUse use1,  Value v2,DataUse use2, BlockMethodCall methodCall) {
		this.branchId = branchId;
		this.switchCaseId =-1;
		this.dataType = dataType;
		this.v1 = v1;
		this.v2 = v2;
		this.use1=use1;
		this.use2=use2;
		this.methodCall= methodCall;
	}
	public Condition(int switchCaseId,Value v1,DataType dataType,DataUse use1){
		this.switchCaseId = switchCaseId;
		this.branchId = -1;
		this.dataType = dataType;
		this.v1 = v1;
		this.v2 = null;
		this.methodCall= null;
		this.use1=use1;
		this.use2=null;

	}
	public Integer getBranchId() {
		return branchId;
	}
	public DataType getType() {
		return dataType;
	}
	/**
	 * @return the 1st value
	 */
	public Value getV1() {
		return v1;
	}
	public DataUse getUse1() {
		return this.use1;
	}
	
	public Value getV2() {
		return v2;
	}
	public DataUse getUse2() {
		return this.use2;
	}
	public BlockMethodCall getMethodCall() {
		if(this.methodCall==null)
			return null;
		return 		this.methodCall;
	}
	@Override
	public final int hashCode() {
		return this.getBranchId();
	}
//	@Override
	public int compareTo(Object o) {
		Condition c = (Condition) o;
		 if (this.branchId < c.branchId) return -1;
		 return 1;
	}
	  public static final Comparator<Condition> SORT_MEMBERS_BY_BRANCHID = new Comparator<Condition>() {
		    public int compare(Condition o1, Condition o2) {
		     // return java.lang.Integer.compare(o1.getBranchId(), o2.getBranchId());
		      return Long.valueOf(o1.getBranchId()).compareTo(Long.valueOf(o2.getBranchId()));
		    
		    }
		  };

	@Override
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append(this.use1==null ?" ":this.use1.toString()+ " ");
		sb.append(this.use2==null ?" ":this.use2.toString()+ " ");
//		sb.append("\n");
//		sb.append(this.getMethodCall()==null?" ":this.getMethodCall()+ " ");
		BlockMethodCall callMethod=this.getMethodCall();
		if(callMethod==null)
			sb.append(this.getV1()==null ?"null":this.getV1().toString()+ " ");
		else{
			sb.append(callMethod.toString()+ " ");
		}
		sb.append(this.getV2()==null ?" ":this.getV2().toString()+ " ");
//		sb.append(this.getType().toString());
//		Class<?> pValueTyp=Filter.getPrimitiveTypeOrString(this.getType().toString());
		

		return sb.toString();
	}

}
